<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search extends CI_Controller {

	function __construct()
	{
		parent::__construct();
	}
	
	/**
	 * 搜索入口
	 */
	public function index()
	{
		$this->lists();
	}
	
	/**
	 * 客户信息列表
	 */
	public function lists()
	{
		$key = $this->input->get('key');
		$page = $this->input->get('per_page');
		$key   = (empty($key))?'':$key;
		$page = (empty($page))?0:intval($page);
		
		$this->load->library('Pager');
		$config['cur_page'] = $page;
		$config['per_page'] = '10'; 
	
		$sql = ($key=='') ? 'select * from archive_idcard' : 'select * from archive_idcard where surname LIKE "%'.$key.'%" or national_id LIKE "%'.$key.'%"'; 
		$sql .= ' order by id desc';
		$this->pager->initialize($config);
		$this->pager->bind_sql($sql);
		$total_rows = $this->pager->get_total_rows();
		$lists = $this->pager->get_page_datas();
		//var_dump($lists);
		
		$this->load->library('pagination');
		$config['base_url'] = "search/lists/?key=".urlencode($key);
		$config['total_rows'] = $total_rows;
		//$config['uri_segment'] = 3;
		$config['page_query_string'] = TRUE;
		//print_r($config);
		$this->pagination->initialize($config); 

		$data = array(
			'key' => $key,
			'lists' => $lists,
			'page' => $this->pagination->create_links()
		);
		$this->load->view('search_lists', $data);
		
	}
	

}

/* End of file search.php */
/* Location: ./application/controllers/search.php */